package com.leenmvc.core.security.entity.core;

import com.leenmvc.core.annotation.DbInfo;
import com.leenmvc.core.annotation.PrimaryKey;
import com.leenmvc.core.annotation.validator.Exist;
import com.leenmvc.core.annotation.validator.Uniqueness;
import com.leenmvc.core.annotation.validator.groups.AddGroup;
import com.leenmvc.core.annotation.validator.groups.DeleteGroup;
import com.leenmvc.core.annotation.validator.groups.UpdateGroup;
import com.leenmvc.core.base.BaseEntity;
import com.leenmvc.core.security.dao.core.SysRolePermissionDao;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * 系统权限
 *
 */
@DbInfo(value = "sys_permission", comment = "权限")
public class SysPermission extends BaseEntity implements Serializable {

    @PrimaryKey
    @Exist(classes = {SysRolePermissionDao.class}, fields = {"permissionId"}, groups = {DeleteGroup.class})
    private Long id;

    @NotBlank(groups = {AddGroup.class, UpdateGroup.class})
    private String name;

    @NotBlank(groups = {AddGroup.class,UpdateGroup.class})
    private String module;

    private String uri;

    @Uniqueness(groups = {AddGroup.class, UpdateGroup.class})
    @NotNull(message = "FIELD_NOT_NULL", groups = {AddGroup.class})
    private String identification;

    public String getUri() {
        return uri;
    }

    public void setUri(String uri) {
        this.uri = uri;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getModule() {
        return module;
    }

    public void setModule(String module) {
        this.module = module;
    }

    public String getIdentification() {
        return identification;
    }

    public void setIdentification(String identification) {
        this.identification = identification;
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }

    public boolean equals(SysPermission obj) {
        return obj.getIdentification().equals(this.identification);
    }
}
